Ext.define('PJ.view.usermessagemanage.Edit', {
	extend: 'AM.default.DefaultWindowForm',
	alias: ['widget.trainingManagementEdit'],
	requires: ['AM.default.DefaultDateField', 
	           'AM.default.DateTime',
	           'AM.default.jsonp.DefaultSubmitJsonp',
	           'AM.default.DefaultDateField'
	           ],
	modal: true,// 开启不允许点击其他组件
	frame: true,
	notEdit: true,
	width: 300,
	height:190,
	layout: 'form',
	isSame: false,
	overflowY:'auto',
	autoScroll:false,
	initComponent: function(){
    	var me = this;
    	
    	var isadmin1 = true;
    	var selectRole = $(document.getElementById("selectRole")).find("option:selected")[0].value;
    	if (selectRole == "business_admin_lv2") {
    		isadmin1 = false;
    	}else {
    		isadmin1 = true;
    	}
    	
    	var bt = '<span style="color:red;">*</span>';
        var theDate = new Date();
        theDate.setFullYear(theDate.getFullYear() + 1, 0, 1);
        if(isadmin1){
        	me.items= [{
	    		defaults: {
	    			labelAlign: 'right',
	    			labelWidth: 90,
	    			columnWidth: .5,
	    			padding:"9 0 0 0",
	    			readOnly:me.isView
	    		},
	    		border: false,
	    		xtype: "container",
	    		width: 270,
	    		height:170,
	    		layout: 'column',
	    		allowBlank: false,
	    		items: [{
	    			xtype: 'textfield',
	    			fieldLabel:'学员账号',
	    			name: 'loginId',
	    			columnWidth:1,
	    			readOnly:true,
	                maxLength: 50,
	    			fieldCls: 'noBorder'
	    		},{
	    			xtype: 'textfield',
	    			fieldLabel:'身份证号',
	    			name: 'paperNum',
	    			regex : /^((11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65|71|81|82|91)\d{4})((((19|20)(([02468][048])|([13579][26]))0229))|((20[0-9][0-9])|(19[0-9][0-9]))((((0[1-9])|(1[0-2]))((0[1-9])|(1\d)|(2[0-8])))|((((0[1,3-9])|(1[0-2]))(29|30))|(((0[13578])|(1[02]))31))))((\d{3}(x|X))|(\d{4}))$/,
					regexText : '请输入正确的身份证号！',
	    			columnWidth:1,
	                maxLength: 50
	    		},{
	    			xtype: 'defaultDate',
	    			fieldLabel:'提任处级时间',
	    			name: 'heldOfficeDateStr',
	    			columnWidth:1,
	                maxLength: 50
	    		},{
	    			xtype: 'hidden',
	    			name: 'userID'//承办部委IDs
	    		}]
	    	}];
        }else{
	        me.items= [{
	    		defaults: {
	    			labelAlign: 'right',
	    			labelWidth: 90,
	    			columnWidth: .5,
	    			padding:"9 0 0 0",
	    			readOnly:me.isView
	    		},
	    		border: false,
	    		xtype: "container",
	    		width: 270,
	    		height:170,
	    		layout: 'column',
	    		allowBlank: false,
	    		items: [{
	    			xtype: 'textfield',
	    			fieldLabel:'学员账号',
	    			name: 'loginId',
	    			columnWidth:1,
	    			readOnly:true,
	                maxLength: 50,
	    			fieldCls: 'noBorder'
	    		},{
	    			xtype: 'textfield',
	    			fieldLabel:bt + '身份证号',
	    			name: 'paperNum',
	    			regex : /^((11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65|71|81|82|91)\d{4})((((19|20)(([02468][048])|([13579][26]))0229))|((20[0-9][0-9])|(19[0-9][0-9]))((((0[1-9])|(1[0-2]))((0[1-9])|(1\d)|(2[0-8])))|((((0[1,3-9])|(1[0-2]))(29|30))|(((0[13578])|(1[02]))31))))((\d{3}(x|X))|(\d{4}))$/,
					regexText : '请输入正确的身份证号！',
	    			allowBlank: false,
	    			columnWidth:1,
	                maxLength: 50
	    		},{
	    			xtype: 'defaultDate',
	    			fieldLabel:'提任处级时间',
	    			disabled:true,
	    			readOnly:true,
	    			name: 'heldOfficeDateStr',
//	    			allowBlank: false,
	    			columnWidth:1,
	                maxLength: 50
	    		},{
	    			xtype: 'hidden',
	    			name: 'userID'//承办部委IDs
	    		}]
	    	}];
	        
        }
        
    	
		this.buttons = [{
			text:"确定",
			scope:this,
//			hidden:me.isReadOnly,
			handler:function(btn){
				var win = me;
				var form = win.down('form');
				var baseForm = form.getForm();
				if (!baseForm.isValid()) {
					return;
				}
				var paperNum = baseForm.findField("paperNum").getValue();
				var loginId = baseForm.findField("loginId").getValue();
//				if (paperNum.length != 18 && paperNum.length != 15) {
//					Orchid.alert('提示','请输入正确的身份证号！');
//					return;
//				}else{
					Ext.Ajax.request({
		                url: me.grid.store.paperNumValidatedUrl,
		                method: 'GET',
		                params:{
		                	paperNum:paperNum,
		                	loginId:loginId
		                },  
		                success: function (response, options) {
		                    classValue=JSON.parse(response.responseText);
		                    if (classValue.success) {
		                    	var url = "";
								var params = {};
								url = me.grid.store.updateUrl;
								if(gj_onlineLearning_constant.loadType == "jsonp"){
									baseForm.doAction('submitJsonp',{
										submitEmptyText: false,//忽略emptyValue
										url: url,
										params: params,
										success: function(f, action){
											if (action.result.success) {
												Orchid.alert('消息', "操作成功!", function(){
													var gridPanel = win.grid;
													var store = gridPanel.getStore();
													store.reload();
													win.close();
												});
											}else{
												Orchid.alert('消息', action.result.msg||"系统出错,请联系管理员!", function(){
													win.close();
												});
											}
										},
										failure: function(f, action){
											Orchid.alert('错误', action.result.msg||"系统出错,请联系管理员!");
										}
									});
								}else{
									form.submit({
										submitEmptyText: false,//忽略emptyValue
										url: url,
										params: params,
										success: function(f, action){
											if (action.result.success) {
												Orchid.alert('消息', "操作成功!", function(){
													var gridPanel = win.grid;
													var store = gridPanel.getStore();
													store.reload();
													win.close();
												});
											}else{
												Orchid.alert('消息', action.result.msg||"系统出错,请联系管理员!", function(){
													win.close();
												});
											}
										},
										failure: function(f, action){
											Orchid.alert('错误', action.result.msg||"系统出错,请联系管理员!");
										}
									});
								}
		                    }else{
		                    	Orchid.alert('提示','该身份证号已重复！');
		                    	return;
		                    }
		                    
		                },
		                failure: function(f, action){
							Orchid.alert('错误', "系统出错,请联系管理员!");
						}
		            });
//				}
			}
		},{
			text: '关闭',
			scope: this,
			hidden:me.isReadOnly,
			handler: this.close
		},{
			text: '关闭',
			scope: this,
			hidden:!me.isReadOnly,
			handler: this.close
		}];
		this.callParent(arguments);
	}
});